package top.didi.study.study.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "threeservlet",urlPatterns = "/three.servlet")
public class ThreeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //编码设置
//        req.setCharacterEncoding("UTF-8");
//        resp.setCharacterEncoding("UTF-8");
        //获取请求中的参数
        String name = req.getParameter("name");
        name = name == null ? "无名氏" : name;
        //应答结果
        resp.setContentType("text/plain");
        PrintWriter out = resp.getWriter();
        out.println("欢迎你，" + name);
        out.close();


    }
}
